package com.yao.controller;

import com.yao.auth.bean.R;
import com.yao.client.OrderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/11/2 14:33
 * FileName: HelloController
 * Description:
 */

@RestController
public class HelloController {

    @RequestMapping("hello")
    public String hello(){
        return "helloworld!";
    }


    @RequestMapping("admin")
    @PreAuthorize("hasAnyAuthority('admin')")
    public String admin(){
        return "admin";
    }

    @RequestMapping("user")
    @PreAuthorize("hasAnyAuthority('ROLE_USER')")
    public String user(){
        return "user";
    }

    @RequestMapping("role")
    @PreAuthorize("hasAnyRole('USER')")
    public String role(){
        return "role";
    }



    @Autowired
    OrderClient orderClient;
    @RequestMapping("order/{orderId}")
    @PreAuthorize(("hasAnyAuthority('ROLE_USER')"))
    public R getOrder(@PathVariable String orderId){

        return orderClient.getOrder(orderId);
    }

}
